<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>自定义事件表单组件</title>
    <script src="../vue.js"></script>
    <script src="../vue-router.js"></script>
</head>

<body>
    <div id="app">
        <first  v-model="price"></first>
    </div>
    <script>
        Vue.component('first',{
            template:'<span>$<input ref="input" v-bind:value="value" v-on:input="updatavalue($event.target.value)"><span>',
            props:['value'],
            methods:{
                updatavalue:function(value){
                    var formattedValue  = value.trim().slice(0,value.indexOf('.')+3);
                    if(formattedValue !==value){
                        this.$refs.input.value=formattedValue
                    };
                    this.$emit('input',Number(formattedValue))
                }
            }
        })
        var app = new Vue({
            el:'#app',
            data (){
                return {
                    price:0
                }
            }
        })
    </script>
</body>

</html>